define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Model = function(){
	    this.phone = '';
	    this.checkOk = false;
		this.callParent();
	};

	Model.prototype.sendSmsCode = function(event){
	
		var phone = this.comp("phone").val();
		var me = this;
		if(phone){
			$.getJSON('http://www.xjzlhy.com:81/ex_community/a/api/community/sendMessage?callback=?&mobile='+phone,
			function(data){
				me.checkOk = true;
				justep.Util.hint('验证码已发送', {type:'success'});
			
			});
			var seconds = 60;
			event.source.set({'label':seconds,'disabled':true});
			var timer = setInterval(function(){
				if(--seconds > 0){
					event.source.set({label:seconds});
				}else{
					event.source.set({'label':'发送','disabled':false});
					clearInterval(timer);
				}
				
			}, 1000);
		}

	};

	Model.prototype.nextStepClick = function(event){
	
		var phone = this.comp("phone").val();
		var checkCode = this.comp("checkCode").val();
		
		if(phone && checkCode && this.checkOk){
		    var me = this;
			$.getJSON('http://www.xjzlhy.com:81/ex_community/a/api/community/sendMessage?callback=?',
			{'mobile':phone,'code':checkCode},
			function(data){
			    me.phone = phone;
			    me.checkOk = true;
			    justep.Util.hint('验证码验证成功', {type:'success'});
				$('.checkCodePanel').hide();
				$('.passwordPanel').show();
			
			});
		
		}

	};

	Model.prototype.resetClick = function(event){
	    
		var newPassword = this.comp("newPassword").val();
		var confirm = this.comp("confirm").val();
		var me  = this;
		if(newPassword && confirm && newPassword == confirm){
			var url = 'http://www.xjzlhy.com:81/ex_community/a/api/community/resetPwd?callback=?';
			$.getJSON(url,
				{newPassword:newPassword,loginName:me.phone},
				function(){
					$('.checkCodePanel').show();
				    $('.passwordPanel').hide();
				    justep.Util.hint('重置密码成功', {type:'success'});
					justep.Shell.closePage();
				}
			);
		}
		

	};


	return Model;
});